package com.hoperun.checkcloth.net;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

public class IServiceImpl {

	public static final String TAG = "IServiceImpl";

	public static final int LOGIN_R = 1;

	public static final int TYPE_querySJZDBySJZDID = 2;
	public static final int TYPE_zjQueryByMonadNo = 3;
	public static final int TYPE_zjClothQtyCheckDetailCommit = 4;
	public static final int TYPE_querySJZDBySJZDID_BZ = 5;
	public static final int GET_NEW_VERSION = 6;
	public static final int TYPE_btQueryByClothtktNo = 7;
	public static final int TYPE_btClothQtyCheckDetailCommit = 8;

	// 材料检验录入
	public static final int TYPE_GETDC = 36;
	public static final int TYPE_getYlzlCheckListInfo = 37;
	public static final int TYPE_getYlzllrUpdateInfo = 38;
	public static final int TYPE_GETDCS = 39;
	public static final int TYPE_saveOrUpdateYlzllr = 30;
	public static final int LOGIN_JIYAN = 40;
	public static final int JY_QUERYLIST = 41;
	public static final int JY_QUERYSANLIAN = 42;
	public static final int JY_SAVELIST = 43;
	public static final int JY_DELETELIST = 44;

	public static final int JY_QUERYZTSANLIAN = 45;
	public static final int JY_SAVEZTLIST = 46;
	public static final int JY_DELETEZTLIST = 47;
	public static final int JY_QUERYZTLIST = 48;

	public static final int JY_SAVECHEJIANLIST = 49;
	public static final int JY_DELETECHEJIANLIST = 50;
	public static final int JY_QUERYCHEJIAN =51;
	public static final int JY_QUERYCHEJIANSANLIAN =52;

	public static final int JY_QUERYFIRST =53;
	public static final int JY_SHUREFIRST =54;
	public static final int JY_NOTSHUREFIRST =55;
	public static final int JY_GETTIME =56;

	public static final int BANG_LOGIN =57;
	public static final int GETINITINFO_R = 58;
	public static final int GETPRODUCTINFO_R = 59;
	public static final int GETISEXISTS_R = 60;

	public static final int GETISSTANDARD_R = 61;

	public static final int ADDPRODUCT_R = 62;
	public static final int BANG_QUERY = 63;
	public static final int ZZ_QUERYLIST = 64;
	public static final int ZZ_SPIINER = 65;

	public static void callWebMethod(final Handler mHandler,
			final int requestType, final Object inputInfo,final String methodName) {
		new Thread() {
			@Override
			public void run() {

				String jsonStr =WebServiceAccessUtils.newcall(methodName,inputInfo.toString() );

				Message msg = Message.obtain();
				msg.what = requestType;
				msg.arg1 = 1;
				try {
					JSONObject json = new JSONObject(jsonStr);

					String falg = json.optString(Setting.OPT_FLAG);
					String info = json.optString("MSG_INFO");

					Log.d(TAG, "OnWebSercieRequest **** info=" + info);

					if (falg.equals("0")) {
						msg.arg1 = 0;
						if (info != null && info instanceof String
								&& info.startsWith("SUCCESS:")) {
							info = info.substring("SUCCESS:".length(),
									info.length());
						}
					} else {
						msg.arg1 = 1;
					}
					if (info != null) {
						msg.obj = info;
					}

					if (info != null && info instanceof String
							&& info.contains("FAILED")) {
						msg.arg1 = 1;
						msg.obj = info;
					}
				} catch (JSONException e) {
					msg.arg1 = 1;
					msg.obj = e.toString();
				}
				mHandler.sendMessage(msg);
			}
		}.start();
	}
}
